//将字符串转换为json
function parseJSON(str) {
    var ret = undefined;
    try {
        ret = eval('(' + str + ')');
    }
    catch (e) { }
    return ret;
}

function isDate(value) {
    var reg = /^(\d{4})\/(\d{1,2})\/(\d{1,2})( (\d{1,2}):(\d{1,2}):(\d{1,2})){0,1}$/;
    var r = value.match(reg);
    if (r == null) return false;
    r[2] = r[2] - 1;
    if (r[5] == undefined) r[5] = 0;
    if (r[6] == undefined) r[6] = 0;
    if (r[7] == undefined) r[7] = 0;
    var d = new Date(r[1], r[2], r[3], r[5], r[6], r[7]); 
    if (d.getFullYear() != r[1]) return false;
    if (d.getMonth() != r[2]) return false;
    if (d.getDate() != r[3]) return false;
    if (d.getHours() != r[5]) return false;
    if (d.getMinutes() != r[6]) return false;
    if (d.getSeconds() != r[7]) return false;
    return true;
}

//转换日期为字符串，includetime:是否包含时间，spit：日期之间的分隔符，默认为-
function DateToString(date, includeTime, spit) {
    if (spit == undefined) spit = '-';
    var ret = date.getFullYear() + spit + date.getMonth() + spit + date.getDay();
    if (includeTime) ret += ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
    return ret;
}

//设置元素尺寸充满父元素
function fitSize(obj,noresizewidth,notresizeheight) {
    var width;
    var height;
    var parentNode = obj.parentNode;
    if (!parentNode || parentNode.tagName=='HTML') {   //body本身
        width = $(window).width();
        height = $(window).height();
    }
    else if (parentNode == document.body) {
        var body = $(document.body);
        var bodyMarginHeight = body.outerHeight(true) - body.height();
        var bodyMarginWidth = body.outerWidth(true) - body.width();
        width = $(window).width() - bodyMarginWidth;
        height = $(window).height() - bodyMarginHeight;
    }
    else {
        width = $(parentNode).width();
        height = $(parentNode).height();
    }
    width -= $(obj).outerWidth(true) - $(obj).width();
    height -= $(obj).outerHeight(true) - $(obj).height();
    if (!noresizewidth) $(obj).width(width)
    if (!notresizeheight) $(obj).height(height);
    //if (!noresizewidth && !notresizeheight) $(obj).css('float', 'left');  //取消外边距叠加
    return { width: width, height: height };
}

//获取当前URL的参数 url：地址，可不传，默认为当前url。c:分隔符，可不传，默认为？
function GetParams(url, c) {
    if (!url) url = location.href;
    if (!c) c = "?";
    url = url.split(c)[1];
    var params = {};
    if (url) {
        var us = url.split("&");
        for (var i = 0, l = us.length; i < l; i++) {
            var ps = us[i].split("=");
            params[ps[0]] = decodeURIComponent(ps[1]);
        }
    }
    return params;
}

//模拟超连接连接到指url
function Href(url, isNewWindow) {
    var a = document.createElement('a');
    a.href = url;
    if (isNewWindow) a.target = '_blank';
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
}

//转换为站外绝对URL
function GetAbsoluteUrl(url) {
    var ret;
    var dt = location.href.split("?")[0].split("/");
    if (url.substr(0, 1) != "/") {
        dt.length--;
        while (url.indexOf("../") == 0) {
            url = url.slice(3);
            dt.length--;
        }
        ret = unescape(dt.join("/") + "/" + url);
    }
    else {
        dt.length = 3;
        ret = unescape(dt.join("/") + url);
    }
    return ret;
}

//解决png 在IE6下的透明问题
function ie6png() {
    for (var i = 0; i < document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i - 1
        };
    };
};


var array = {
    RemoveAt: function (value, index) {
        for (var i = index; i < value.length - 1; i++) {
            value[i] = value[i + 1];
        }
        value.pop();
    }
}

var StringMethod =
{
    Trim: function (value) {
        return this.TrimLeft(this.TrimRight(value));
    },
    TrimLeft: function (value) {
        if (value.length > 0) {
            while (value.substr(0, 1) == ' ') {
                value = value.substr(1);
            }
        }
        return value;
    },
    TrimRight: function (value) {
        if (value.length > 0) {
            while (value.substr(value.length - 1) == ' ') {
                value = value.substr(0, value.length - 1);
            }
        }
        return value;
    },
    ReplaceAll: function (value, instr, repstr) {
        if (value.length > 0) {
            while (value.indexOf(instr) > -1) {
                value = value.replace(instr, repstr);
            }
        }
        return value;
    },
    Left: function (value, length) {
        if (value.length > 0) {
            value = value.substr(0, length);
        }
        return value;
    },
    Right: function (value, length) {
        if (value.length > 0) {
            value = value.substr(value.length - length);
        }
        return value;
    }
}